import os

def list_files_in_wrong_folders(root_dir, output_file):
    with open(output_file, "w") as f:
        for root, dirs, files in os.walk(root_dir):
            if "wrong" in dirs:
                wrong_folder_path = os.path.join(root, "wrong")
                f.write(f"Files in {os.path.relpath(wrong_folder_path, root_dir)}:\n")
                for subdir_root, subdir_dirs, subdir_files in os.walk(wrong_folder_path):
                    for file_name in subdir_files:
                        f.write(os.path.join(os.path.relpath(subdir_root, wrong_folder_path), file_name) + "\n")


# 源路径A
root_dir = "/home/champrin/Desktop/MV-CS016-10UC+DA1041860/给预备役/json_annotations (copy)/goo 分批收集/finish check"
output_file = os.path.join(root_dir, "output.txt")

# 统计所有子文件夹中"wrong"文件夹内的文件，并输出到txt文件
list_files_in_wrong_folders(root_dir, output_file)